package tw.edu.tku.im.maze;

import org.json.JSONException;
import org.json.JSONObject;

import android.os.Parcel;
import android.os.Parcelable;

public class AddRoomRep extends RepPacket {

   int state;
   int roomID;
   
   //-------------------------------------------------------
   public AddRoomRep(int state) {
      this.state = state;
      this.roomID = 0;
   }
   
   public AddRoomRep(int state, int roomID) {
      this.state = state;
      this.roomID = roomID;
   }
   
   //-------------------------------------------------------
   public int getState() {
      return this.state;
   }
   public void setState(int state) {
      this.state = state;
   }
   
   //-------------------------------------------------------
   public int getRoomID() {
      return this.roomID;
   }
   public void setRoomID(int roomID) {
      this.roomID = roomID;
   }
   
   //-------------------------------------------------------
   public String toString() {
      StringBuilder ans = new StringBuilder("{ \"state\" : ");
      ans.append(this.state).append(", \"roomID\" : ")
         .append(this.roomID).append(" }");
      return ans.toString();
   }
   
   public String toJSONString() throws JSONException {
      JSONObject jsonObj = new JSONObject();
      JSONObject result = new JSONObject();
      result.put("state", this.state);
      if(this.roomID!=0) {
         result.put("roomID", this.roomID);
      }
      jsonObj.put("result", result);
      jsonObj.put("action", "addRoomResponse");
      return jsonObj.toString();
   }

   @Override
   public String getPacketName() {
      return "addRoomResponse";
   }

   @Override
   public int describeContents() {
      return 0;
   }

   @Override
   public void writeToParcel(Parcel arg0, int arg1) {
     
   }

}
